public class Solution831 {
    public String maskPII(String s) {
        if (s.contains("@")){
            s=s.toLowerCase();
            String temp=s.substring(0,s.indexOf("@"));
            StringBuilder stringBuilder=new StringBuilder();
            stringBuilder.append(temp.charAt(0));
            for (int i=0;i<5;i++){
                stringBuilder.append('*');
            }
            stringBuilder.append(temp.charAt(temp.length()-1));
            return stringBuilder.append(s.substring(s.indexOf('@'))).toString();
        }else{
            char[] chars={'+', '-', '(', ')', ' '};
            for (char aChar : chars) {
                s=s.replace(String.valueOf(aChar),"");
            }
            String target;
            if (s.length()==10){
                target="***-***-";
            }else if (s.length()==11){
                target="+*-***-***-";
            }else if (s.length()==12){
                target="+**-***-***-";
            }else{
                target="+***-***-***-";
            }
            target=target.concat(s.substring(s.length()-4));
            return target;
        }
    }

    public static void main(String[] args) {
        System.out.println(new Solution831().maskPII("86-(10)12345678"));
    }
}
